﻿using System;
using System.Collections.Generic;
using System.Text;

public class FuelEngine : Engine
{
    private eEngineFuelType m_engineFuelType;

    public eEngineFuelType EngineFuelType
    {
        get { return m_engineFuelType; }
        set { m_engineFuelType = value; }
    }

    private float m_CurrentFuelLevel;

    private float m_MaxFuelLevel;

    public FuelEngine(eEngineFuelType i_EngineFuelType, float i_EngineFuelCapacity)
    {
        m_engineFuelType = i_EngineFuelType;
        m_MaxFuelLevel = m_CurrentFuelLevel = i_EngineFuelCapacity;
        this.EngineType = eEngineType.Fuel;
    }

    public void LoadFuel(eEngineFuelType i_FuelTypeToLoad, float i_FuelAmmountToLoad)
    {
        if (this.EngineFuelType.Equals(i_FuelTypeToLoad))
        {
            if (i_FuelAmmountToLoad + m_CurrentFuelLevel <= m_MaxFuelLevel)
            {
                m_MaxFuelLevel = i_FuelAmmountToLoad;
            }
            else
            {
                throw new ValueOutOfRangeException("The amount is higher than the fuel tank", 0, m_MaxFuelLevel);
            }
        }
        else
        {
            throw new System.FormatException("You are trying to fuel the vehicle with incorrect fuel type");
        }
    }

    public enum eEngineFuelType
    {
        Soler = 0,
        Octan95,
        Octan96,
        Octan98
    }

    public new virtual string ToString()
    {
        string ResultStr = base.ToString();
        string[] PropertiesStrArray = new string[] { "Fuel type: ", m_engineFuelType.ToString(), System.Environment.NewLine, "Current fuel level: ", m_CurrentFuelLevel.ToString(), System.Environment.NewLine };

        ResultStr = string.Concat(ResultStr, PropertiesStrArray);
        return ResultStr;
    }
}
